// import promise from 'es6-promise'
// promise.polyfill()
import Vue from 'vue'
import 'normalize.css/normalize.css' // A modern alternative to CSS resets
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import './styles/element-variables.scss'
import '@/styles/index.scss' // global css

import App from './App'
import router from './router/routers'
import i18n from './lang' // internationalization
import permission from './components/permission'
import VModal from 'vue-js-modal'

import dict from './components/Dict'
import DataGridTable from './components/DataGridTable/index'
import CustomDialog from './components/CustomDialog/CustomDialog'
import DataGridColumn from './components/DataGridTable/DataGridColumn'
import DataGridColumnSlot from './components/DataGridTable/DataGridColumnSlot'
import DataGridColumnDict from './components/DataGridTable/DataGridColumnDict'

import DataGridOpts from './components/DataGridOpts/index'
import DestoryOpt from './components/DataGridOpts/DestoryOpt'
import FileUpload from '@/views/components/FileUpload'
import IconHelp from './components/IconHelp/index'
import splitPane from 'vue-splitpane'
import { getToken } from '@/utils/auth'
// import kzTable from '@kuaizi/kz-table'

Vue.prototype.$getToken = function() {
  return getToken()
}

import store from './store'

import '@/icons' // icon
import './router/index' // permission control
Vue.use(ElementUI, {
  i18n: (key, value) => i18n.t(key, value),
  size: 'mini'
})

// Vue.use(mavonEditor)
Vue.use(VModal, {
  dialog: true,
  dynamic: true,
  injectModalsContainer: true,
  dynamicDefaults: {
    clickToClose: false
  }
})

// Vue.component(kzTable.name, kzTable)
Vue.component('DataGridTable', DataGridTable)
Vue.component('DataGridColumn', DataGridColumn)
Vue.component('DataGridColumnSlot', DataGridColumnSlot)
Vue.component('DataGridColumnDict', DataGridColumnDict)

Vue.component('CustomDialog', CustomDialog)
Vue.component('DataGridOpts', DataGridOpts)
Vue.component('DestoryOpt', DestoryOpt)
Vue.component('FileUpload', FileUpload)
Vue.component('IconHelp', IconHelp)
Vue.component('split-pane', splitPane)

Vue.use(permission)
Vue.use(dict)

// Vue.use(ElementUI, { locale })
Vue.config.productionTip = false
// require('babel-polyfill')

new Vue({
  el: '#app',
  router,
  store,
  i18n,
  render: h => h(App)
})

if (
  '-ms-scroll-limit' in document.documentElement.style &&
  '-ms-ime-align' in document.documentElement.style
) { // detect it's IE11
  window.addEventListener('hashchange', function(event) {
    var currentPath = window.location.hash.slice(1)
    if (store.state.route.path !== currentPath) {
      router.push(currentPath)
    }
  }, false)
}
